package cn.thread;

public class StopTest implements Runnable{
    private boolean flag=true;
    private String name;
    public StopTest(String name){
        this.name=name;
    }
    public static void main(String args[]){
        StopTest s=new StopTest("高山青");
        new Thread(s).start();
        for(int i=0;i<100;i++){

            if(i==80){
                s.stop();
            }
            System.out.println("main方法的线程"+i);
        }
    }

    @Override
    public void run() {
        int i=0;
        while(flag){
            System.out.println(name+"-->"+i++);
        }
    }
    public void stop(){
        this.flag=false;
        System.out.println(name+"结束进程");
    }
}
